import { makeAutoObservable } from 'mobx';
import { getClassInfo ,allPageNum,replyRightAnswer, waitPageNum, selectAnswerList, qualityAnswerId, deleteQualityAnswerId, answerList, answerDetail, reply} from '@/services/index';
import {IGetClassInfoData, IAllParams, IAllPageNumData,IQuestionIdList, ISelectParams,ISelectPageNumData, IAnswerParams, IAnswerList, IAnswerDetailData, IReply} from '@/utils/manageInterface';

class Manage{
  constructor() {
    makeAutoObservable(this)
  }
  getClassInfoData: IGetClassInfoData[] = [];
  allPageNumData: IAllPageNumData[] = [];
  selectPageNumData: ISelectPageNumData[] = [];
  total = 1;
  answerListData: IAnswerList[] = [];
  answerDetailData:IAnswerDetailData = {} as IAnswerDetailData;

  async getClassInfo(){
    let res = await getClassInfo();
    if (res.data) {
      this.getClassInfoData=res.data
    }
    return res
  }
  async waitPageNum(params:IAllParams){
    let res = await waitPageNum(params);
    if (res.rows) {
      this.allPageNumData = res.rows;
      this.total=res.total;
    }
    return res.rows
  }
  async allPageNum(params:IAllParams){
    let res = await allPageNum(params);
    if (res.rows) {
      this.allPageNumData = res.rows;
      this.total=res.total;
    }
    return res.rows
  }
  async selectAnswerList(params:ISelectParams){
    let res = await selectAnswerList(params);
    if (res.rows) {
      this.selectPageNumData = res.rows;
      this.total=res.total;
    }
    return res.rows
  }
  async answerList(params:IAnswerParams){
    let res = await answerList(params);
    if (res.rows) {
      this.answerListData = res.rows;
      this.total=res.total;
    }
    return res.rows
  }
  async replyRightAnswer(data:IQuestionIdList){
    let res = await replyRightAnswer(data);
    return res;
  }
  async qualityAnswerId(id:string){
    let res = await qualityAnswerId(id);
    return res;
  }
  async deleteQualityAnswerId(id:string){
    let res = await deleteQualityAnswerId(id);
    return res;
  }
  //详情
  async answerDetail(id:string){
    let res = await answerDetail(id);
    this.answerDetailData = res.data;
    return res.data;
  }
  //详情回答
  async reply(data:IReply){
    let res = await reply(data);
    // this.answerDetailData = res.data;
    return res;
  }

}
export default new Manage